//
//  DPressure ViewController.m
//  dance
//
//  Created by aether on 2023/10/20.
//

#import "DPressureViewController.h"

@interface DPressureViewController ()

@property (nonatomic, strong) IBOutlet UIView *bg;
@property (nonatomic, weak) IBOutlet UIView *loginBg;
@property (nonatomic, weak) IBOutlet UITextField *systolicText;
@property (nonatomic, weak) IBOutlet UITextField *diastolicText;
@property (nonatomic, weak) IBOutlet UILabel *remind;
@property (nonatomic, weak) IBOutlet UITextView *formula;

@end

@implementation DPressureViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    
//    [self initViews];
}

- (void) initViews {
    CAGradientLayer *gl = [CAGradientLayer layer];
    gl.frame = CGRectMake(0, 0, CGRectGetWidth(self.view.frame) + 20, CGRectGetHeight(self.view.frame));
    gl.startPoint = CGPointMake(0.5, 0);
    gl.endPoint = CGPointMake(0.5, 1);
    gl.colors = @[(__bridge id)[UIColor colorWithRed:71/255.0 green:0/255.0 blue:233/255.0 alpha:1.0].CGColor, (__bridge id)[UIColor colorWithRed:51/255.0 green:149/255.0 blue:247/255.0 alpha:0.0].CGColor];
    gl.locations = @[@(0), @(1.0f)];
    [self.bg.layer addSublayer:gl];
    
    CAGradientLayer *gl1 = [CAGradientLayer layer];
    gl1.frame = CGRectMake(0, 0, CGRectGetWidth(self.loginBg.frame) + 20, CGRectGetHeight(self.loginBg.frame));
    gl1.startPoint = CGPointMake(0, 0.5);
    gl1.endPoint = CGPointMake(1, 0.5);
    gl1.colors = @[(__bridge id)[UIColor colorWithRed:1/255.0 green:140/255.0 blue:255/255.0 alpha:1.0].CGColor, (__bridge id)[UIColor colorWithRed:68/255.0 green:57/255.0 blue:229/255.0 alpha:1.0].CGColor];
    gl1.locations = @[@(0), @(1.0f)];
    self.loginBg.layer.cornerRadius = 7;
    self.loginBg.layer.masksToBounds = YES;
    [self.loginBg.layer addSublayer:gl1];
    
    [self.formula setText:@"收缩压 >= 90 且 舒张压 <= 119 或 收缩压 >= 60 且 舒张压 <= 79 您的血压正常 \n 收缩压 >= 120 且 舒张压 <= 139 或 收缩压 >= 80 且 舒张压 <= 89 您可能有轻度高血压 \n 收缩压 >= 140 且 舒张压 <= 159 或 收缩压 >= 90 且 舒张压 <= 99 您可能有中度高血压 \n 收缩压 >= 160 且 舒张压 <= 100 您可能有重度高血压 \n 此数据仅供参考，在做出医疗决定之前应该咨询医生"];
}

- (void)viewDidLayoutSubviews {
    [super viewDidLayoutSubviews];
    
    [self initViews];
}

#pragma mark - 代理方法

- (BOOL) textFieldShouldReturn:(UITextField *)textField {
    return true;;
}

#pragma mark - 事件

- (IBAction) computeClicked:(id)sender {
    
    
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"提示" message:@"该功能开发中，敬请期待" preferredStyle:UIAlertControllerStyleAlert];

    UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"提示" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        // 处理确定按钮的操作
    }];

    [alertController addAction:okAction];
    [self presentViewController:alertController animated:YES completion:nil];
    return;
    
    int systolic = [self.systolicText.text intValue];
    int diastolic = [self.diastolicText.text intValue];
    
    if (systolic >= 90 && systolic <= 119 && diastolic >= 60 && diastolic <= 79) {
        self.remind.text = @"您的血压正常。";
    } else if (systolic >= 120 && systolic <= 139 && diastolic >= 80 && diastolic <= 89) {
        self.remind.text = @"您可能有轻度高血压。";
    } else if (systolic >= 140 && systolic <= 159 && diastolic >= 90 && diastolic <= 99) {
        self.remind.text = @"您可能有中度高血压。";
    } else if (systolic >= 160 && diastolic >= 100) {
        self.remind.text = @"您可能有重度高血压。";
    } else {
        self.remind.text = @"您的血压不在正常范围内，请咨询医生。";
    }
}

@end
